package com.ybfenpan.controller.member;


import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.service.MemberService;
import com.ybfenpan.utils.ContextUtil;
import com.ybfenpan.utils.SysConst;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.HashMap;


@Controller
public class UserManageController extends BaseController {

	@Resource 
	private MemberService memberService;
	 
	 
	@RequestMapping("/member/userManage.shtml")
	public String memberLogin(HttpServletRequest request, HttpServletResponse response, Model model) {
		 
		Member member = ContextUtil.getMember();
		if (member != null) {
			return "member/userManage";
		} else {
			return "login";
		 
		}
		

	}
	
	
	@RequestMapping("/member/alive.shtml")
	@ResponseBody
	public void ajax(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
		
		Boolean result = true;
		Member member = ContextUtil.getMember();
		member= memberService.getByKey(member.getId());
		
		session.setAttribute(SysConst.MEMBER, member);
		
		HashMap resultformMap = new HashMap();
		
		if (member == null||member.getAccountUse().equals("F")||"F".equals(member.getAccountActive())) {
			
			result=false;
		} else {
			resultformMap.put("zh", member.getLoginName()); 		//账户
			resultformMap.put("jjb", member.getMoney());			//现金积分
			resultformMap.put("jf", member.getStore());			 	
			resultformMap.put("zcb", member.getEle());
			 
			 
			String levelTitle = "";
			if(member.getLevel()==1){
				levelTitle="普通业务员";
			}else if(member.getLevel()==2){
				levelTitle="金牌业务员";
			}else if(member.getLevel()==3){
				levelTitle="主任";
			}else if(member.getLevel()==4){
				levelTitle="经理";
			}else if(member.getLevel()==4){
				levelTitle="总监";
			}else if(member.getLevel()==4){
				levelTitle="董事";
			}else if(member.getLevel()==4){
				levelTitle="双董事";
			}		
			resultformMap.put("xsjb", levelTitle);
		 
			 
			
			SimpleDateFormat formatter = new SimpleDateFormat("MM月dd日 HH:mm");
			String jhsj = formatter.format(member.getActiveDate());
			resultformMap.put("jhsj", jhsj);
		}
		
		
		resultformMap.put("result", result);
		renderSuccess(response, true, resultformMap);
	}
	
	 
	
}
